package com.yilin.tms.capital.commons.strategy.tools;


import com.yilin.commons.exception.BusinessException;
import com.yilin.tms.capital.commons.strategy.operation.BankOperation;
import com.yilin.tms.capital.service.IWeCartService;
import com.yilin.tms.core.entity.capital.TradeRecord;
import com.yilin.tms.core.entity.user.account.Account;

import java.util.List;

// 微信支付
 public class WeChatOperation implements BankOperation {//添加需要在BankOperationFactory.class添加判断
    private final IWeCartService weCartService;

    public WeChatOperation(IWeCartService weCartService) {
        this.weCartService = weCartService;
    }

    /**
     * 支付
     * */
    @Override
    public void execute(List<TradeRecord> tradeRecordList, Account account) {
        throw  new BusinessException("微信支付禁止使用策略模式");
    }
    /**
     * 退款
     * */
    @Override
    public TradeRecord executeRefund(TradeRecord tradeRecord, Account account) {
        return weCartService.weChatRefund(account, tradeRecord);
    }
    /**
     * 查询
     * */
    @Override
    public TradeRecord executeQuery(TradeRecord tradeRecord, Account account) {
        if (tradeRecord.getTradeType() == TradeRecord.TradeType.payment) {
            tradeRecord = weCartService.queryWeChatPayOrder(account, tradeRecord);
        } else if (tradeRecord.getTradeType() == TradeRecord.TradeType.refund) {
            tradeRecord = weCartService.weChatRefundQuery(account, tradeRecord);
        }
        return tradeRecord;
    }
}
